#include <kernel/kobject.h>
#include <kernel/initcall.h>
#include <kernel/syslog.h>
#include <mm/mem.h>

static bool kobj_print_current_dir(kobj_t *kobj)
{
    kobj_t *kobj_node;
    struct list_node *head = &kobj->child;

    if(kobj_is_dir(kobj)) {
        list_for_each_entry(kobj_node, head, kobj_t, entry) {
            SYSLOG_INFO("%s ", kobj_node->name);
        }
    }
}


static bool kobj_foreach_all(kobj_t *kobj)
{
    if(kobj == NULL) {
        return false;
    }

    kobj_t *kobj_node;
    struct list_node *head = &kobj->child;

    if(kobj_is_dir(kobj)) {
        list_for_each_entry(kobj_node, head, kobj_t, entry) {
            kobj_foreach_all(kobj_node);
        }
    }

    SYSLOG_INFO("%s", kobj->name);
    return true;
}


int kobj_test(void)
{
    kobj_t *root = kobj_get_root();

    kobj_t* node_a = kobj_create_dir(root, "A");
    kobj_create_dir(root, "B");
    kobj_t *kb = kobj_create_dir(root, "C");
    kobj_create_attr(kb, "A", NULL);

    //kobj_remove_self(kb);
    

    kobj_foreach_all(root);

    //kmalloc(10000000);

    return 0;
}


module_initcall(kobj_test);
